package com.wudl.govern.controller;

import com.wudl.common.api.CommonResult;
import com.wudl.govern.domain.MappingField;
import com.wudl.govern.domain.MappingSource;
import com.wudl.govern.domain.MappingTable;
import com.wudl.govern.service.MetaAtlasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：wudl
 * @date ：Created in 2022-04-04 22:46
 * @description：元数据图谱
 * @modified By：
 * @version: 1.0
 */

@RestController
@RequestMapping("/metaAtlas")
public class MetaDataAtlasController {


    @Autowired
    MetaAtlasService metadataAtlasAddService;


    /**
     * 元数据图谱-添加`字段`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/insert_mapping_field_list
     * @Title: mappingField
     * @Description:
     * @param:
     * 		[
     * 		{
     *       		"mappingTableId":33,
     *             "initFieldId":1,
     *             "targetFieldId":2,
     *             "initFieldName":"初始字段名称55",
     *             "targetFieldName":"目标字段名称55",
     *             "mappingType":2,
     *             "remarks":"备注5"
     *       	},{
     *       		"mappingTableId":33,
     *             "initFieldId":1,
     *             "targetFieldId":2,
     *             "initFieldName":"初始字段名称66",
     *             "targetFieldName":"目标字段名称66",
     *             "mappingType":2,
     *             "remarks":"备注6"
     *       	}
     * 	]
     * @return
     * @return:
     */
    @PostMapping("/insert_mapping_field_list")
    public CommonResult selectList(@RequestBody List<MappingField> mappingFieldList){
         metadataAtlasAddService.insertMappingField(mappingFieldList);
        return CommonResult.success();
    }

    /**
     *元数据图谱-添加`库`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/insert_mapping_source_list
     * @Title: mappingSource
     * @Description:
     * @param:
     * 	[
     * 		{
     *       		"initCompany":"初始归口单位",
     *             		"initSourceId":1,
     *             		"targetSourceId":2,
     *             		"initSourceName":"初始数据源name",
     *             		"targetSourceName":"目标数据源name",
     *             		"mappingType":2,
     *             		"remarks":"备注"
     *       	},
     *       	{
     *       		"initCompany":"初始归口单2位",
     *             		"initSourceId":2,
     *             		"targetSourceId":3,
     *             		"initSourceName":"初始数据源name2",
     *             		"targetSourceName":"目标数据源name2",
     *             		"mappingType":2,
     *             		"remarks":"备注2"
     *       	}
     * 	]
     * @return
     * @return:
     */
    @PostMapping("/insert_mapping_source_list")
    public CommonResult insertMappingSource(@RequestBody List<MappingSource> mappingSourceList){
        metadataAtlasAddService.insertMappingSource(mappingSourceList);
        return CommonResult.success();
    }

    /**
     * 元数据图谱-添加`表`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/insert_mapping_table_list
     * @Title: mappingTable
     * @Description:
     * @param:
     * 	[
     * 		{
     *       		"mappingSourceId":1,
     *            		"initTableId":3,
     *             		"targetTableId":2,
     *             		"initTableName":"初始表名称55",
     *             		"targetTableName":"目标表名称55",
     *             		"mappingType":2,
     *             		"remarks":"备注"
     *       	},{
     *       		"mappingSourceId":1,
     *            		"initTableId":3,
     *             		"targetTableId":2,
     *             		"initTableName":"初始表名称6",
     *             		"targetTableName":"目标表名称6",
     *             		"mappingType":2,
     *             		"remarks":"备注6",
     *             	"targetSourtceId":69
     *       	}
     * 	]
     * @return
     * @return:
     */
    @PostMapping("/insert_mapping_table_list")
    public Object insertMappingTable(@RequestBody List<MappingTable> mappingTableList){
        metadataAtlasAddService.insertMappingTable(mappingTableList);
        return CommonResult.success();
    }


    /**
     *元数据图谱-删除`库`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/deleteMappingSource
     * @Title: mappingSource
     * @Description:
     * @param:
     *
     * 		{
     *
     *             		"targetSourceId":2
     *       	}
     *
     * @return
     * @return:
     */
    @PostMapping("/deleteMappingSource")
    public Object deleteMappingSourceState(@RequestBody Map map){
        metadataAtlasAddService.deleteMappingSourceState(map);
        return CommonResult.success();
    }


    /**
     *元数据图谱-删除`表`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/deleteMappingTable
     * @Title: mappingSource
     * @Description:
     * @param:
     **[
     * 		{
     *
     *             	"targetSourtceId":381
     *             	"targetTableId":"257"
     *       	},
     *         {
     *
     *             	"targetSourtceId":381
     *             	"targetTableId":"106"
     *       	}
     *
     *]
     * @return
     * @return:
     */
    @PostMapping("/deleteMappingTable")
    public Object deleteMappingTable(@RequestBody List<MappingTable> mappingTableList){
         metadataAtlasAddService.deleteMappingTable(mappingTableList);
        return CommonResult.success();
    }


    /**
     *元数据图谱-删除`字段`信息功能
     * http://127.0.0.1:6063/isky-config-service/metadata_atlas_add/deleteMappingField
     * @Title: mappingSource
     * @Description:
     * @param:
     **[
     * 		{
     *
     *             	"targetTableId":381
     *             	"targetFieldId":"257"
     *       	},
     *         {
     *
     *             	"targetTableId":381
     *             	"targetFieldId":"106"
     *       	}
     *
     *]
     * @return
     * @return:
     */
    @PostMapping("/deleteMappingField")
    public Object deleteMappingField(@RequestBody List<MappingField> mappingTableList){
        metadataAtlasAddService.deleteMappingField(mappingTableList);
        return CommonResult.success();
    }
    
}
